package research.model;

import java.util.ArrayList;
import java.util.List;

import research.domain.Photo;
import research.domain.Production;
import research.domain.SampleStabilizer;
import research.domain.Scratch;
import research.domain.Stabilizer;
import research.domain.Strength;
import research.domain.Test;
import research.domain.Viscosity;
import research.domain.Research;
import research.domain.Sample;
import research.entity.Entity;
import research.entity.EntityType;

public class ResearchHierarchy extends ListHierarchy {
	public ResearchHierarchy() {
		super(EntityType.Research);
		types.add(EntityType.Production);
		types.add(EntityType.Stabilizer);
		types.add(EntityType.Sample);
		types.add(EntityType.Test);
		types.add(EntityType.Strength);
		types.add(EntityType.Viscosity);
		types.add(EntityType.Photo);
		types.add(EntityType.Scratch);
		types.add(EntityType.SampleStabilizer);
		
	}

	@Override
	public List<Entity> getChildren(Entity entity) {
		List<Entity> list = new ArrayList<Entity>();
		if (entity instanceof Research) {
			Research res = (Research) entity;
			list.addAll(res.getProductions());
			list.addAll(res.getStabilizers());
		} else if (entity instanceof Production) {
			Production res = (Production) entity;
			list.addAll(res.getSamples());
		} else if (entity instanceof Sample) {
			Sample res = (Sample) entity;
			list.addAll(res.getPhotos());
			list.addAll(res.getScratches());
			list.addAll(res.getStrengths());
			list.addAll(res.getViscosities());
			list.addAll(res.getTests());
			list.addAll(res.getSampleStabilizers());
		} /*else if (entity instanceof Stabilizer) {
			Stabilizer res = (Stabilizer) entity;
			list.addAll(res.getSampleStabilizers());
		} */
		return list;
	}

	@Override
	public Entity getParent(Entity entity) {
		if (entity instanceof Production) {
			Production res = (Production) entity;
			return res.getResearch();
		}else if (entity instanceof Sample) {
			Sample res = (Sample) entity;
			return res.getProduction();
		} else if (entity instanceof Stabilizer) {
			Stabilizer res = (Stabilizer) entity;
			return res.getResearch();
		} else if (entity instanceof SampleStabilizer) {
			SampleStabilizer res = (SampleStabilizer) entity;
			return res.getSample();
		} else if (entity instanceof Photo) {
			Photo res = (Photo) entity;
			return res.getSample();
		} else if (entity instanceof Scratch) {
			Scratch res = (Scratch) entity;
			return res.getSample();
		} else if (entity instanceof Strength) {
			Strength res = (Strength) entity;
			return res.getSample();
		} else if (entity instanceof Viscosity) {
			Viscosity res = (Viscosity) entity;
			return res.getSample();
		} else if (entity instanceof Test) {
			Test res = (Test) entity;
			return res.getSample();
		}
		return null;
	}

	@Override
	public boolean hasChildren(Entity entity) {
		return entity instanceof Research || entity instanceof Sample || entity instanceof Production;
	}

}
